<?php
namespace Qwadmin\Model;
class OrderModel extends \Think\Model{
    public function __construct() {
        
    }
    
    /**
     *  获取列表
     */
    public function getList($page = 1 , $where = []){
        $pageSize = 20 ;
        $count = M("view_order")->where($map)->count("id");
        $offset = ($page - 1) * $pageSize; 
        $list = M("view_order")->where($where)->order("response_time desc")
                              ->limit($offset . "," . $pageSize)
                              ->select();
        
        $pagebar = new \Think\Page($count, $pageSize);
        return [
            'list'  => $list ,
            'page'  => $pagebar->show()
        ];
        
    }
    
    /**
     *  统计总金额
     */
    public function totalMoney(){
        if(session("uid") != 1){
            $map['refid'] = session("uid");
        }
        $map['status'] = 1 ;
        $total_money = M("view_order")->where($map)->sum("money");
        
        return $total_money;
    }
    
    /**
     *  统计订单总数
     */
    public function countOrder(){
        if(session("uid") != 1){
            $map['refid'] = session("uid");
        }
        $map['status'] = 1 ;
        $count = M("view_order")->where($map)->count("id");
        
        return $count;
    }
    
}
